<template>
  <a-card :bordered="false">
    <a-spin :spinning="loading">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :xxl="4" :xl="6">
              <a-form-item label="名称">
                <a-input placeholder="输入名称/助记号码模糊搜索" v-model="queryParam.name"></a-input>
              </a-form-item>
            </a-col>
          
            <a-col :xxl="4" :xl="6">
              <a-form-item label="编码">
                <a-input placeholder="精准搜索" v-model="queryParam.code"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xxl="4" :xl="6">
              <a-form-item label="医保编码">
                <a-input placeholder="精准搜索" v-model="queryParam.medicalCatalogCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xxl="4" :xl="6">
              <a-form-item label="批文编号/机械准字号">
                <a-input placeholder="精准搜索" v-model="queryParam.approvalNumber"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xxl="4" :xl="6">
              <a-form-item label="生产厂家">
                <a-input placeholder="模糊搜索" v-model="queryParam.manufacturer"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xxl="4" :xl="6">
              <a-form-item label="医品医材类型">
                <j-dict-select-tag v-model="queryParam.project" dictCode="prescription_project" />
              </a-form-item>
            </a-col>
            <a-col :xxl="4" :xl="6">
              <a-form-item label="对照上传">
                <j-dict-select-tag v-model="queryParam.miFlag" dictCode="miFlag_status" />
              </a-form-item>
            </a-col>
             <a-col :xxl="4" :xl="6">
              <a-form-item label="目录对照">
                <j-dict-select-tag v-model="queryParam.hasMiCodeFlag" dictCode="drug_mulu_status" />
              </a-form-item>
            </a-col>
            <a-col :xxl="4" :xl="6">
              <a-form-item label="启用状态">
                <!-- <a-input placeholder="模糊搜索" v-model="queryParam.name"></a-input> -->
                <j-dict-select-tag v-model="queryParam.enabledFlag" dictCode="depart_status" />
              </a-form-item>
            </a-col>
            <a-col :xxl="4" :xl="6">
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 查询区域-END -->

      <!-- 操作按钮区域 -->
      <div class="table-operator">
        <a-button @click="handleAdd" type="primary" icon="plus">新增（F2）</a-button>
        <a-popconfirm title="确定批量上传对照关系吗?" @confirm="()=> handleUploadGX()" v-if="getConfigStatus('mi')">
          <a-button type="primary" icon="shrink">批量上传对照关系</a-button>
        </a-popconfirm>
        <a-button @click="handleUpload" type="primary" icon="upload"  v-has="'upload:admin'">导入</a-button>
        <a-button @click="handleCatalogAdd" type="warning" icon="diff">医保目录添加</a-button>
        <a-popconfirm title="确定删除吗?" @confirm="() => batchDel()">
            <a-button type="danger" v-if="selectedRowKeys.length > 0"> 删除 <a-icon type="delete" /></a-button>
        </a-popconfirm>
      </div>

      <!-- table区域-begin -->
      <div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </div>

        <a-table
          ref="table"
          size="middle"
          :scroll="{x:true}"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          class="j-table-force-nowrap"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
          @change="handleTableChange">
          
          <template slot="htmlSlot" slot-scope="text">
            <div v-html="text"></div>
          </template>
          <template slot="imgSlot" slot-scope="text">
            <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
            <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
          </template>
          <template slot="fileSlot" slot-scope="text">
            <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
            <a-button
              v-else
              :ghost="true"
              type="primary"
              icon="download"
              size="small"
              @click="downloadFile(text)">
              下载
            </a-button>
          </template>

          <span slot="action" slot-scope="text, record">
            <a @click="handleEdit(record)">编辑</a>

            <a-divider type="vertical" />
            <a-dropdown>
              <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
              <a-menu slot="overlay">
                <a-menu-item v-if="record.enabledFlag+'' === '1'">
                  <a-popconfirm title="确定禁用吗?" @confirm="() => handleSetEable(record)">
                    <a>禁用</a>
                  </a-popconfirm>
                </a-menu-item>
                <a-menu-item v-if="record.enabledFlag+'' !== '1'">
                  <a-popconfirm title="确定启用吗?" @confirm="() => handleSetEable(record)">
                    <a>启用</a>
                  </a-popconfirm>
                </a-menu-item>
                <a-menu-item>
                  <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                    <a>删除</a>
                  </a-popconfirm>
                </a-menu-item>
                <a-menu-item>
                  <a @click="handleSetPrice(record)">调价</a>
                </a-menu-item>
                <a-menu-item>
                  <a @click="handleSetCode(record)">重新对码</a>
                </a-menu-item>
                <a-menu-item>
                  <a @click="handleSetUpDown(record)">上下限调整</a>
                </a-menu-item>
                <a-menu-item>
                  <a @click="handleSetJiacheng(record)">加成调整</a>
                </a-menu-item>
                <a-menu-item>
                  <a @click="handleSetTicheng(record)">提成调整</a>
                </a-menu-item>
              </a-menu>
            </a-dropdown>
          </span>

        </a-table>
      </div>
      <setmiCodeModal ref="micodeModal"  @ok="handleCatalogOk"></setmiCodeModal>
      <wh-drug-western-modal ref="modalForm" @ok="modalFormOk"></wh-drug-western-modal>
      <setPriceModal ref="modalPrice" @ok="modalPriceOk"></setPriceModal>
      <uploadModal ref="uploadDom" @ok="modalPriceOk"></uploadModal>
      <setUpDownModal ref="upDownDom" @ok="modalPriceOk"></setUpDownModal>
      <setJiachengModal ref="JiachengDom" @ok="modalPriceOk"></setJiachengModal>
      <setTichengModal ref="TichengDom" @ok="modalPriceOk"></setTichengModal>
      <J-select-biz-component-modal ref="selectModal" v-bind="modalProps"  v-model="selectValue"
        :visible.sync="modalvisible" listUrl="wh/drugWestern/miSearch"
        @getv="bizValChange" :columns="gyscolumns" :queryParamCode="['keyword','approvalNumber','code','manufacturer','name','pinyinCode']" :pamaName="'keyword'" :queryParamText="['关键字','批准文号','编码','生产企业','名称','助记码']">
      </J-select-biz-component-modal>
    </a-spin>
  </a-card>
</template>

<script>
  import JSelectBizComponentModal from '@/components/jeecgbiz/JSelectBizComponent3/JSelectBizComponentModal'
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { yaodianMinxin } from '@/mixins/yaodianMinxin'
  import WhDrugWesternModal from './modules/WhDrugWesternModal'
  import setPriceModal from './modules/setPriceModal'
  import uploadModal from './modules/uploadModal'
  import setUpDownModal from './modules/setUpDownModal.vue'
  import setJiachengModal from './modules/setJiachengModal.vue'
  import setTichengModal from './modules/setTichengModal.vue'
  import setmiCodeModal from './modules/setmiCodeModal.vue'
  import { otherKeyMinxin } from '@/mixins/otherKeyMinxin'

  export default {
    props:['keyIndex'],
    name: 'WhDrugWesternList',
    mixins:[JeecgListMixin, mixinDevice,yaodianMinxin,otherKeyMinxin],
    components: {
      WhDrugWesternModal,
      setPriceModal,
      uploadModal,
      JSelectBizComponentModal,
      setUpDownModal,
      setJiachengModal,
      setTichengModal,
      setmiCodeModal
    },
    data () {
      return {
        description: '药典-西药表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            fixed:'left',
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'名称',
            align:"center",
            dataIndex: 'name',
            width:200,
            fixed:'left',
            scopedSlots: { customRender: 'name' }
          },
          {
            title:'医品医材类型',
            align:"center",
            dataIndex: 'project',
            width:120,
            scopedSlots: { customRender: 'project' }
          },
          {
            title:'编码',
            align:"center",
            dataIndex: 'code',
            scopedSlots: { customRender: 'code' }
          },
          {
            title:'医保名称',
            align:"center",
            dataIndex: 'medicalCatalogName',
            width:200,
            scopedSlots: { customRender: 'medicalCatalogName' }
          },
          {
            title:'医保编码',
            align:"center",
            dataIndex: 'medicalCatalogCode',
            scopedSlots: { customRender: 'medicalCatalogCode' }
          },
          {
            title:'总剂量',
            align:"center",
            dataIndex: 'specification',
            scopedSlots: { customRender: 'specification' }
          },
          {
            title:'库存数量',
            align:"center",
            dataIndex: 'stockQuantity',
            scopedSlots: { customRender: 'stockQuantity' }
          },
          {
            title:'规格',
            align:"center",
            dataIndex: 'specificationDescribe',
            scopedSlots: { customRender: 'specificationDescribe' }
          },
          {
            title:'包装单位',
            align:"center",
            dataIndex: 'packUnit_dictText',
            scopedSlots: { customRender: 'packUnit' }
          },
          {
            title:'批准文号',
            align:"center",
            dataIndex: 'approvalNumber',
            scopedSlots: { customRender: 'approvalNumber' }
          },
          {
            title:'生产厂家',
            align:"center",
            dataIndex: 'manufacturer',
            width:200,
            scopedSlots: { customRender: 'manufacturer' }
          },
          {
            title:'处方药',
            align:"center",
            dataIndex: 'prescriptionFlag_dictText',
            scopedSlots: { customRender: 'prescriptionFlag' }
          },
          {
            title:'零售价',
            align:"center",
            dataIndex: 'retailPrice',
            scopedSlots: { customRender: 'retailPrice' }
          },
          {
            title:'单品提成',
            align:"center",
            dataIndex: 'singleCommission',
            scopedSlots: { customRender: 'singleCommission' }
          },
          {
            title:'收费等级',
            align:"center",
            dataIndex: 'miLevel',
            scopedSlots: { customRender: 'miLevel' }
          },
          {
            title:'医保对照上传状态',
            align:"center",
            dataIndex: 'miFlag',
            customRender: function (text) {
              if (text == 1) {
                return '已上传'
              } else {
                return '未上传'
              }
            },
            scopedSlots: { customRender: 'miFlag' }
          },
          {
            title:'销售标识',
            align:"center",
            dataIndex: 'saleFlag',
            customRender: function (text) {
              if (text == 1) {
                return '已销售'
              } else {
                return '未销售'
              }
            },
            scopedSlots: { customRender: 'saleFlag' }
          },
          {
            title:'启用状态',
            align:"center",
            dataIndex: 'enabledFlag_dictText',
            scopedSlots: { customRender: 'enabledFlag' }
          },
          {
            title:'是否拆零',
            align:"center",
            dataIndex: 'trdnFlag',
            customRender: function (text) {
              if (text+'' === '1') {
                return '是'
              } else {
                return '否'
              }
            },
            scopedSlots: { customRender: 'trdnFlag' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/wh/drugWestern/list",
          delete: "/wh/drugWestern/delete",
          deleteBatch: "/wh/drugWestern/deleteBatch",
          exportXlsUrl: "/wh/drugWestern/exportXls",
          importExcelUrl: "wh/drugWestern/import",
          switchstate:'wh/drugWestern/switchState',
          miBatchUpload:'wh/drugWestern/miBatchUpload',
          CatalogAdd:'sys/util/miWesternCatalogAdd',
          
        },
        dictOptions:{},
        gyscolumns: [
          { title: '医保编码', dataIndex: 'medicalCatalogCode', align: 'center', width: '55%' },
          { title: '医保名称', dataIndex: 'medicalCatalogName', align: 'center', width: '45%' },
          { title: '名称', dataIndex: 'name', align: 'center', width: '45%' },
          { title: '批准文号', dataIndex: 'approvalNumber', align: 'center', width: '45%' },
          { title: '生产厂家', dataIndex: 'manufacturer', align: 'center', width: '45%' },
          { title: '剂量', dataIndex: 'dose', align: 'center', width: '45%' },
          { title: '包装单位', dataIndex: 'packUnit', align: 'center', width: '45%' },
          { title: '零售价格', dataIndex: 'retailPrice', align: 'center', width: '45%' },
          { title: '药品规格', dataIndex: 'drugSpecification', align: 'center', width: '45%' },
          { title: '包装数量', dataIndex: 'packageQuantity', align: 'center', width: '45%' },
          { title: '收费等级', dataIndex: 'miLevel', align: 'center', width: '45%' },
        ],
        codeurls:'wh/drugWestern/recode',
      }
    },
    created() {
     
    },
    
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
      
  
    },
    methods: {
      // areAllModalsHidden() {
      //   let obj = {

      //   }
      //   this.dataSource.unshift(obj)
      // },
      initDictConfig(){
      },
      
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
  .ant-btn-danger {
    color: #fff;
    background-color: #f5222d;
    border-color: #f5222d;
  }
</style>